package com.xu.vo;

import com.xu.resultenum.RCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 徐老板
 * @date 2020/3/30   23:00
 * 返回给前端的状态信息类
 */
@Data
public class R implements Serializable {
    private Integer code;
    private String msg;
    private Object data;

    public static R setR(boolean state,String msg,Object ojb){
        R r =new R();
        if (state){
            r.setCode(RCode.SUCCESS.getCode());
        }else {
            r.setCode(RCode.ERROR.getCode());
        }
        r.setMsg(msg);
        r.setData(ojb);
        return r;
    }

//   接下来写成功和失败的方法
    public static R ok(Object obj){
        return setR(true, "OK", obj);
    };
    public static R fail(){
        return setR(false, "ERROR", null);
    };
}
